<html>
	<head>
		<link media="screen" href="qunit.css" type="text/css" rel="stylesheet">
		<script src="require.js"></script>
		<script src="qunit.js"></script>

		<script>

			QUnit.config.autostart = false;

            require({
			    paths: {
			        'jmodel': '../library/'
			    }
			});

			require(['test-sapphire.js'], function (tests) {
				QUnit.start();
		    });
			
		</script>

		<!--script>
		
			// ------------------------------------------------------------------------
			//																		Set
			// ------------------------------------------------------------------------
			
			module('Set');
			
			test('Getting elements', function () {
				
			});
		
			test('First element', function () {
				
				var testSet = opal.set();
				
				equals( testSet.first(), false, 'empty set has no first element');
				
				testSet.add('red');
				testSet.add('green');
				
				equals( testSet.first(), 'red', 'first element of non-empty set is first added');
				
			});
			
			test('Selector', function () {
			
				var testSet = opal.set();
				testSet.add('red');
				testSet.add('green');
				
				equals( testSet.select(':first'), 'red', ':first selector returns first added');
				equals( testSet.select('fred'), testSet, 'other selectors return whole set' );
				
				
			});
			
			test('Each', function () {
			
				var testSet = opal.set();
				testSet.add('red');
				testSet.add('green');
				testSet.add('blue');
				
				var concat = '';
				testSet.each(function (item) {concat+=item});
				
				equals( concat, 'redgreenblue', 'each works with functions');
				
				var testSet = opal.set();
				var concatstr = '';
				var concat = function () {concatstr+=this.colour};
				
				var red = new Object();
				red.colour = 'red';
				red.concat = concat;
				
				var green = new Object();
				green.colour = 'green';
				green.concat = concat;
				
				testSet.add(red);
				testSet.add(green);
				testSet.each('concat')
				
				equals(concatstr, 'redgreen', 'each works with method name');
				
			});
			
			test('When', function () {
			
				var testSet = opal.set(),
					output;
				
				testSet.when(':empty', function () { output = 123 });
				equals(output, 123, 'when works with :empty on empty set' );
				
				testSet.add('red');
				output = null;
				testSet.when(':empty', function () { output = 123 });
				equals(output, null, 'when works with :empty on non-empty set' );
				
			});
		
			test('Partition', function () {
			
				var testSet = opal.set(1,2,3,4,5,6,7,8),
					partition = testSet.partition(function (object) {
						return object % 2 == 0;
					},'even','odd');
				
				equals(partition.odd.first(), 1, 'fail contains correct first element');
				equals(partition.odd.count(), 4, 'fail contains correct number of elements');
				
				equals(partition.even.first(), 2, 'pass contains correct first element');
				equals(partition.even.count(), 4, 'pass contains correct number of elements');
				
			});
			
			test('Filter', function () {
				
				// Test filter with no parameter
				var testSet = opal.set(1,2,3,4);
				equals( testSet.filter(), testSet, 'Filtering with no conditions leaves set unchanged');
				
				// Test filter with string-specified selector
				equals( testSet.filter(':first'), 1, 'Filtering with string-specified selector applies selector' );
				
				// Test filter with predicate and no selector
				equals( testSet.filter(function (obj) {return obj <= 2}).count(), 2, 'Filtering removes objects' );
				equals( testSet.filter(function (obj) {return obj >= 2}).first(), 2, 'Filtering preserves objects' );
				
				// Test filter with predicate and selector
				equals( testSet.filter(function (obj) {return obj >= 2},':first'), 2, 'Filtering with selection works' );
				
			});
			
			test('Map', function () {
				
				var testSet = opal.set(1,2,3),
				    double  = function (obj) { return obj*2; },
				    addten  = function (obj) { return obj+10;};
				
				equals(testSet.map(double).count(), 3, 'Map returns list with correct cardinality');
				equals(testSet.map(double).first(), 2, 'Map correctly maps first element');
				equals(testSet.map(double,addten).count(), 3, 'Pipeline mapping returns list with correct cardinality');
				equals(testSet.map(double,addten).first(), 12, 'Pipeline mapping maps first element correctly');
				
			});
			
			test('Reduce', function () {
				
			});
			
			test('Copy', function () {
				var testSet = opal.set('red','green','blue'),
					copied = testSet.copy();
					
				equals(copied.first(), 'red', 'copying preserves first element');
				
				testSet.remove(function (obj) { return obj === 'red' });
				equals(copied.first(), 'red', 'changes to original set membership not propagated');
			
			});
			
			test('Join', function () {
				var testSet = opal.set('red','green','blue');
				equals(testSet.join(','), 'red,green,blue', 'join works');
			});
		
			test('Union', function () {
				var testSet = opal.set('red','green','blue');
				equals( testSet.union(opal.set('cyan','magenta')).count(), 5, 'Union with one set works' );
				equals( testSet.union(opal.set('cyan','magenta'),opal.set('yellow')).count(), 6, 'Union with multiple sets works' );
			});
			
			test('Intersection', function () {
				var testSet = opal.set('red','green','blue');
				equals( testSet.intersection(opal.set('red','blue')).count(), 2, 'Intersection with one set works' );
				equals( testSet.intersection(opal.set('red','blue'),opal.set('blue')).count(), 1, 'Intersection with multiple sets works' );
			});
			
			test('Difference', function () {
				var testSet = opal.set('red','green','blue');
				equals( testSet.difference(opal.set('red')).count(), 2, 'Difference has correct first number of element' );
				equals( testSet.difference(opal.set('red')).first(), 'green', 'Difference has correct first element' );
			});
			
			test('Predicate generator', function () {
				// Need lots of assertions here
			});
			
			test('Ordering generator', function () {
				
			});
			
			test('Indexing', function () {
				
			});
			
			test('Formatting', function () {
				
			});
			
			test('Delegation', function () {
				// Need lots of assertions here
			});
		
			test('Set creation', function () {
				
			});
		
			// ------------------------------------------------------------------------
			// 															 Set operations
			// ------------------------------------------------------------------------
			
			module('Set operations');
			
			test('Union', function () {
				var set1 = opal.set('red','green','blue'),
					set2 = opal.set('cyan','magenta','yellow'),
					set3 = opal.set('black','white');
				equals( opal.union(set1,set2,set3).count(), 8, 'Union of multiple sets has correct cardinality' );
			});
			
			test('Intersection', function () {
				var set1 = opal.set('red','green','blue'),
					set2 = opal.set('red','blue'),
					set3 = opal.set('blue');
				equals( opal.intersection(set1,set2,set3).count(), 1, 'Intersection of multiple sets has correct cardinality');
				equals( opal.intersection(set1,set2,set3).first(), 'blue', 'Intersection of multiple sets contains correct elements');
			});
			
			test('Difference', function () {
				var set1 = opal.set('red','green','blue'),
					set2 = opal.set('red','blue');
				equals( opal.difference(set1,set2).count(), 1, 'Difference has correct cardinality');
				equals( opal.difference(set1,set2).first(), 'green', 'Difference has correct membership');
			});
			
		
			// ------------------------------------------------------------------------
			// 															   Unique index
			// ------------------------------------------------------------------------
		
			module('Unique Index');
		
			test('Index creation', function () {
				
			});
			
			test('Index rebulding', function () {
				
			});
			
			test('Index add', function () {
				
			});
			
			test('Index remove', function () {
				
			});
			
			test('Index get', function () {
				
			});
		
		

			// ------------------------------------------------------------------------
			// 																 Predicates
			// ------------------------------------------------------------------------
			
			module('Predicates');
			
			
			test('Predicates generator: predicate', function () {
				
				var predicate = opal.ObjectIdentityPredicate('Dummy');
				same( opal.predicate(predicate), predicate, 'opal.predicate should return actual predicates unchanged' );
				
			});
			
			
			test('Predicates generator: object identity', function () {
				
				var object = {name:'Fred'};
				equals( opal.predicate(object)(object), opal.ObjectIdentityPredicate(object)(object), "acting on predicate's object" );
				equals( opal.predicate(object)({}), opal.ObjectIdentityPredicate(object)({}), "acting on predicate's object" );
			
			});
			
			
			test('Predicates generator: null', function () {
				
				var object = {Forename:'Test1'};
				equals( opal.predicate(null)(object),  true, "should return AllPredicate when passed null" );
			
			});
			
			
			test('AllPredicate', function () {
				
				var object = {Forename:'Test1'};
				equals( opal.AllPredicate(object), true, "returns true on generic object" );
			
			});
			
			
			test('NonePredicate', function () {
				
				var object = {Forename:'Test1'};
				equals( opal.NonePredicate(object), false, "returns false on generic object" );
			
			});
			
			
			test('TruePredicate', function () {
			
			});
			
			
			test('FunctionPredicate', function () {

				var match   = {First:3,Second:2};
				var nomatch = {First:3,Second:3};
				var fn = function (candidate) {
					return candidate.First+candidate.Second == 5
				}
				equals( opal.FunctionPredicate(fn)(match), true, "returns true on matching object" );
				equals( opal.FunctionPredicate(fn)(nomatch), false, "returns false on umatching object" );
			
			});
			
			
			test('FunctionValuePredicate', function () {
			
			});
			
			test('TypePredicate', function () {
				// Need lots of assertions here
			});
			
			test('PropertyPredicate', function () {
			
				var person = {Forename:'John'};
				
				equals( opal.PropertyPredicate('Forename','John')(person), true, 'returns true if property matches' );
				equals( opal.PropertyPredicate('Forename','Jane')(person), false, 'returns false if property matches' );
				
				var person = {Name:{Fore:'John'}};
				
				equals( opal.PropertyPredicate('Name.Fore','John')(person), true, 'returns true if property path matches' );
				equals( opal.PropertyPredicate('Name.Fore','Jane')(person), false, 'returns false if property path does not matches' );
				
			});
			
			
			test('PropertySetPredicate', function () {
			
			});
			
			
			test('ComparisonPredicate', function () {
				
			});
			
			
			test('between', function () {
				// Need lots of assertions here
			});
			
			
			test('RegularExpressionPredicate', function () {
				// Need lots of assertions here
			});
			
			
			test('MembershipPredicate', function () {
				
				var red = 'red',
					green = 'green',
					blue = 'blue',
					pink = 'pink',
					testSet = opal.set(red,green,blue);
					
				equals( opal.MembershipPredicate(testSet)(red), true, "returns true if object is first in collection");
				equals( opal.MembershipPredicate(testSet)(green), true, "returns true if object is elsewhere in collection");
				equals( opal.MembershipPredicate(testSet)(pink), false, "returns false if object is not in collection");
				
			});
			
			
			test('Or', function () {
				// Need lots of assertions here
			});
			
			
			test('And', function () {
				// Need lots of assertions here
			});
			
			
			test('Not', function () {
				// Need lots of assertions here
			});
			
			
			test('EmptySetPredicate', function () {
				// Need lots of assertions here
			});
			
			
			test('AllSetPredicate', function () {
				// Need lots of assertions here
			});
			
			
			test('SomeSetPredicate', function () {
				// Need lots of assertions here
			});
			
			
			test('NoneSetPredicate', function () {
				// Need lots of assertions here
			});
			
			
			test('CardinalityPredicate', function () {
				// Need lots of assertions here
			});
			
			
			// ------------------------------------------------------------------------
			// 																  Orderings
			// ------------------------------------------------------------------------
		
			module('Orderings');
			
			
			test('Orderings generator', function () {
				// Need lots of assertions here
			});	
			
			test('PredicateOrdering', function () {
				// Need lots of assertions here
			});

 		</script-->
	</head>
	<body>
		<h1>Sapphire JavaScript Tests</h1>
		<h2 id="qunit-banner"></h2>
		<div id="qunit-testrunner-toolbar"></div>
		<h2 id="qunit-userAgent"></h2>
		<ol id="qunit-tests"></ol>
		<div id="qunit-fixture">test markup, will be hidden</div>
	</body>
</html>